package think.thread.sychron.c02;

public class WaitPerson implements Runnable{
	
	private Restaurant restaurant;
	
	public WaitPerson(Restaurant restaurant){
		this.restaurant=restaurant;
	}
	
	public void run() {
		
		try {
			while(!Thread.interrupted()){
				synchronized (this) {
					while(restaurant.meal==null){
						wait();
					}
				}
				System.out.println("wait person got the "+restaurant.meal);
				
				synchronized (restaurant.chef) {
					restaurant.meal=null;
					restaurant.chef.notifyAll();
				}
			}
		} catch (Exception e) {
//			e.printStackTrace();
			System.out.println("waitperson interrupted");
		}
		
	}
	
}
